package fr.web325.servlet.api.user;

import fr.web325.bean.Json;
import fr.web325.dao.UserDao;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/api/activation")
public class Activation extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取激活码
        String code = req.getParameter("ActivationCode");
        JSONObject json = new JSONObject();
        JSONObject data = new JSONObject();
        // 控制Dao激活用户
        try {
            if(new UserDao().editUserStatus(code)){
                // 激活成功
                resp.getWriter().print(new Json(200,null,"激活成功!").getRespJson());
            }else{
                // 激活失败
                resp.getWriter().print(new Json(200,null,"激活失败,请检查激活码是否正确!").getRespJson());
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
